class Observer {
    constructor(data) {
        this.walk(data)
    }
    walk(data) {
        if (!data || typeof data !== 'object') {
            return
        }
        Object.keys(data).forEach(item => {
            this.defineReactive(data, item, data[item])
        })
    }
    defineReactive(obj, key, val) {
        this.walk(val)
        let that = this
        Object.defineProperty(obj, key, {
            enumerable: true,
            configurable: true,
            get() {
                return val
            },
            set(newval, oldval) {
                if (newval === oldval) {
                    return
                }
                val = newval
                that.walk(newval)
            }
        })
    }
}